package com.demo.ping.utils


import spock.lang.Specification

class CaesarCipherTest extends Specification {

    def "encrypt should return correct encrypted string"() {
        given: "A plain text and a key"
        String plainText = "Hello,World!"
        int key = 3

        when: "The text is encrypted"
        String encryptedText = CaesarCipher.encrypt(plainText, key)

        then: "The encrypted text should not be null and should not equal the original text"
        encryptedText != null
        encryptedText != plainText

        and: "The decrypted text should match the original text"
        String decryptedText = CaesarCipher.decrypt(encryptedText, key)
        decryptedText == plainText
    }

    def "decrypt should return correct decrypted string"() {
        given: "An encrypted text and a key"
        String encryptedText = "123456"
        int key = 3

        when: "The text is decrypted"
        String decryptedText = CaesarCipher.decrypt(encryptedText, key)

        then: "The decrypted text should not be null and should match the original text"
        decryptedText != null
        decryptedText == "./0123"
    }

    def "encrypt and decrypt should work correctly with negative key"() {
        given: "A plain text and a negative key"
        String plainText = "123456"
        int key = -3

        when: "The text is encrypted"
        String encryptedText = CaesarCipher.encrypt(plainText, key)

        then: "The encrypted text should not be null and should not equal the original text"
        encryptedText != null
        encryptedText != plainText

        and: "The decrypted text should match the original text"
        String decryptedText = CaesarCipher.decrypt(encryptedText, key)
        decryptedText == plainText
    }
}
